//
//  MainTabBarController.swift
//  SinaWeiBo
//
//  Created by 谭淇 on 15/3/5.
//  Copyright (c) 2015年 &#35885;&#28103;. All rights reserved.
//

import UIKit

class MainTabBarController: UITabBarController {

    @IBOutlet weak var mainTabBar: MainTabBar!
    
    override func viewDidLoad() {
        super.viewDidLoad()

        mainTabBar.compose = {
            println("hello")
        }
        
        //  添加子控制器
        addControllers()
    }
    
    ///  添加子控制器
    func addControllers() {
        // 使用代码添加视图控制器
        addChildController("Home", "首页", imageName: "tabbar_home", highlighted: "tabbar_home_highlighted")
        addChildController("Message", "消息", imageName: "tabbar_message_center", highlighted: "tabbar_message_center_highlighted")
        addChildController("Discover", "发现", imageName: "tabbar_discover", highlighted: "tabbar_discover_highlighted")
        addChildController("Profile", "我", imageName: "tabbar_profile", highlighted: "tabbar_profile_highlighted")
    }

    ///  添加视图控制器
    ///
    ///  :param: name        storyboard名称
    ///  :param: title       标题
    ///  :param: imageName   图片
    ///  :param: highlighted 高亮图片
    func addChildController(name: String, _ title: String, imageName: String, highlighted: String) {
        let sb = UIStoryboard(name: name, bundle: nil)
        let vc = sb.instantiateInitialViewController() as! UINavigationController
        vc.tabBarItem.image = UIImage(named: imageName)
        vc.tabBarItem.selectedImage = UIImage(named: highlighted)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        vc.title = title
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orangeColor()], forState: UIControlState.Selected)
        self.addChildViewController(vc)
    }

}
